<!--
 * @FilePath     : /layui/demo/1534.html
 * @Description  : 主动打开/关闭下拉框
 * @Date         : 2025-02-24 10:08
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-02-24 10:09
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div style="width: 200px; float: left">
      <div id="demo1" class="xm-select-demo"></div>
    </div>
    <div style="width: 100px; float: left">
      <button class="btn" id="demo1-open">打开下拉框</button>
      <button class="btn" id="demo1-close">关闭下拉框</button>
    </div>

    <script src="/xm-select/dist/xm-select.js"></script>
    <script>
      var demo1 = xmSelect.render({
        el: '#demo1',
        data: [
          { name: '张三', value: 1 },
          { name: '李四', value: 2 },
          { name: '王五', value: 3 },
        ],
      })

      document.getElementById('demo1-open').onclick = function () {
        //这里延迟1S, 是因为, 点击下拉框外边的位置 会出发关闭事件, 所以延迟演示效果
        setTimeout(function () {
          demo1.opened()
        }, 1000)
      }

      document.getElementById('demo1-close').onclick = function () {
        //先点一下关闭, 然后把下拉框点开, 3S后会自动关闭
        setTimeout(function () {
          demo1.closed()
        }, 3000)
      }
    </script>
  </body>
</html>
